package com.zjhs.affluence.controller;

import com.zjhs.affluence.entity.${ClassName};
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zjhs.base.mybatisplus.PageQuery;
import com.zjhs.common.dto.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zjhs.affluence.service.I${ClassName}Service;
import javax.validation.Valid;
import java.util.List;

/**
 * ${table.comment}
 */
@Slf4j
@Api(value = "/${className}",tags = " ${table.comment}")
@RestController
@RequestMapping("/${className}")
public class ${ClassName}Controller {

	@Autowired
	private I${ClassName}Service ${className}Service;

	@ApiOperation(value = "集合查询[通用][带分页][getList]", notes = "集合查询[通用][带分页]")
	@PostMapping("/getList")
	public Result<List<${ClassName}>> getList(@RequestBody PageQuery pageQuery) {
		IPage<${ClassName}> pageList = ${className}Service.getList(pageQuery);
        return Result.data(pageList.getRecords(),pageList.getTotal());
    }

    @ApiOperation(value = "单条查询[依据id]", notes = "单条查询[依据id]")
    @GetMapping("{id}")
	public Result<${ClassName}> getById(@PathVariable Long id) {
        ${ClassName} entity = ${className}Service.get(id);
        return Result.data(entity);
    }

	@ApiOperation(value = "新增[通用]", notes = "新增[通用]")
    @PostMapping()
	public Result add(@Valid @RequestBody ${ClassName} ${className}) {
        return ${className}Service.insert(${className});
    }

    @ApiOperation(value = "更新[通用]", notes = "更新[通用]")
    @Deprecated
    @PutMapping()
	public Result update(@Valid @RequestBody ${ClassName} ${className}) {
        return ${className}Service.update(${className});
    }

    @ApiOperation(value = "删除[根据id]", notes = "删除[根据id]")
    @DeleteMapping("{id}")
	public Result delete(@PathVariable Long id) {
        return ${className}Service.deleteById(id);
    }




}
